package leetCode;

import java.util.Stack;

public class T20 {
    public static void main(String[] args) {
        System.out.println(new SolutionT20().isValid("()"));
    }
}
class SolutionT20 {

    Stack<Character>stack=new Stack<>();

    public boolean isValid(String s) {
        char[] sChars = s.toCharArray();
        for (char sChar:sChars){
            if (sChar=='('||sChar=='['||sChar=='{'){
                stack.push(sChar);
            }else if(stack.isEmpty()){
                return false;
            }else if (sChar==')'&&stack.pop()=='('||sChar=='}'&&stack.pop()=='{'||sChar==']'&&stack.pop()=='['){
                continue;
            }else {
                return false;
            }
        }
        return stack.isEmpty();
    }
}